Skip to content

fix(obligation_creation): pass user name in context for the db call w…#128

Closed
mayank-pathakk wants to merge 1 commit intofossology:mainfrom
mayank-pathakk:mayank-fixObligations
Closed

fix(obligation_creation): pass user name in context for the db call w…#128
mayank-pathakk wants to merge 1 commit intofossology:mainfrom
mayank-pathakk:mayank-fixObligations

Conversation

@mayank-pathakk
Copy link
Copy Markdown

@mayank-pathakk mayank-pathakk commented Mar 25, 2025

…hile creating obligations

Changes

As mentioned in the associated issue we were getting the following error:
username not found in context. This was due to the hook we had in our license model.

func (l *LicenseDB) BeforeCreate(tx *gorm.DB) error {
	username, ok := tx.Statement.Context.Value(ContextKey("user")).(string)
	if !ok {
		return errors.New("username not found in context")
	}
	...
}

Now since we were not passing the user in the context, we were unable to figure out the username and hence we were getting the error.

Submitter Checklist

  • Includes tests (if there is a feature changed/added)
  • Includes docs ( if changes are user facing) [Nothing changes for the end user]
  • I have tested my changes locally.

References

Screenshot 2025-03-25 at 3 54 49 PM

@mayank-pathakk
Copy link
Copy Markdown
Author

@GMishx @deo002 Please review. This change would include the user name in the context and hence will fix the issue.
Thanks in advance.

@ChayanDass
Copy link
Copy Markdown
Contributor

ChayanDass commented Mar 25, 2025

Hi @mayank-pathakk sir,
yes, this will solve the issue but the issue is beforecreate hook for license should not be called during creation of obligation....

@deo002
Copy link
Copy Markdown
Collaborator

deo002 commented Jul 9, 2025

Closing in favour of #122

@deo002 deo002 closed this Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

obligations creating error with shortnames

3 participants